//
//  AddProductModel.m
//  quickBatchManager
//
//  Created by 王定波 on 15/9/28.
//  Copyright © 2015年 jack. All rights reserved.
//

#import "AddProductModel.h"
#import "UploadData.h"
@implementation AddProductModel
+(NSString *)getTableName
{
    return @"qbm_addproduct";
}


+(NSString *)getPrimaryKey
{
    return @"addProductId";
}


-(void)setProductId:(NSInteger)productId
{
    _productId=productId;
    _product=[ProductModel searchSingleWithWhere:@{@"productId":[ToolUtils numberToStr:productId]} orderBy:nil];
}

-(void)setBatchId:(NSInteger)batchId
{
    _batchId=batchId;
    _batchProduct=[BatchProductModel searchSingleWithWhere:@{@"batchId":[ToolUtils numberToStr:batchId]} orderBy:nil];
}



+(void)dbDidInserted:(NSObject*)entity result:(BOOL)result
{
    if([entity isKindOfClass:[AddProductModel class]])
    {
        AddProductModel *model = (AddProductModel *)entity;
        UploadData *data = [[UploadData alloc] init];
        data.t_table = [AddProductModel getTableName];
        data.t_opType = DB_INSERT;
        data.t_pkName = [self getPrimaryKey];
        data.t_pk = model.rowid;
        data.t_time = [[NSDate date] timeIntervalSince1970InMilliSecond];
        model.addProductId = data.t_pk;
        NSMutableDictionary *params = model.keyValues;
        [params removeObjectForKey:@"batchProduct"];
        [params removeObjectForKey:@"product"];
        NSString *value = [self DataTOjsonString:params];
        data.content = value;
        [UploadData insertToDB:data];
    }
   // NSLog(@"DB 插入数据成功");
    
    
}

+(void)dbDidUpdated:(NSObject*)entity result:(BOOL)result
{
    if([entity isKindOfClass:[AddProductModel class]])
    {
        AddProductModel *model = (AddProductModel *)entity;
        UploadData *data = [[UploadData alloc] init];
        data.t_table = [AddProductModel getTableName];
        data.t_opType = DB_UPDATE;
        data.t_pkName = [self getPrimaryKey];
        data.t_pk = model.rowid;
        data.t_time = [[NSDate date] timeIntervalSince1970InMilliSecond];
        model.addProductId = data.t_pk;
        NSMutableDictionary *params = model.keyValues;
        [params removeObjectForKey:@"batchProduct"];
        [params removeObjectForKey:@"product"];
        NSString *value = [self DataTOjsonString:params];
        data.content = value;
        [UploadData insertToDB:data];
    }
   // NSLog(@"DB 更新数据");
}


+(void)dbDidDeleted:(NSObject*)entity result:(BOOL)result
{
    if([entity isKindOfClass:[AddProductModel class]])
    {
        AddProductModel *model = (AddProductModel *)entity;
        UploadData *data = [[UploadData alloc] init];
        data.t_table = [AddProductModel getTableName];
        data.t_opType = DB_DELETE;
        data.t_pkName = [self getPrimaryKey];
        data.t_pk = model.rowid;
        data.t_time = [[NSDate date] timeIntervalSince1970InMilliSecond];
        model.addProductId = data.t_pk;
        NSMutableDictionary *params = model.keyValues;
        [params removeObjectForKey:@"batchProduct"];
        [params removeObjectForKey:@"product"];
        NSString *value = [self DataTOjsonString:params];
        data.content = value;
        [UploadData insertToDB:data];
    }
   // NSLog(@"DB 删除数据");
}

@end
